package HomeWork1;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class TestStudent {

    public static void main(String[] args) {
        Student student1 = new Student("林启汶", 169);
        Student student2 = new Student("李华生", 168);
        Student student3 = new Student("万雨能", 173);
        Student student4 = new Student("甘金泉", 172);
        Student student5 = new Student("布威热比", 167);

        Student student = max(student1, student2, new ComparatorStudent());
        System.out.println("最大年龄是：" + student.getHeight());

        List<Student> studentArayList = new ArrayList<Student>();
        studentArayList.add(student1);
        studentArayList.add(student2);
        studentArayList.add(student3);
        studentArayList.add(student4);
        studentArayList.add(student5);

        Collections.sort(studentArayList, new ComparatorStudent());
        Collections.reverse(studentArayList);
        Collections.max(studentArayList, new ComparatorStudent());

        for (Student item : studentArayList){
            System.out.println("姓名:" + item.getName() + "   " + "身高:" + item.getHeight());
        }
    }

    public static Student max(Student g1,Student g2,Comparator<Student> c){
        if (c.compare(g1,g2) > 0)
            return g1;
        else
            return g2;
    }
}
